package day20180131.designMode.ten_Proxy;

/**
 * Created by 14394 on 2018/1/31.
 */
//目标接口
public interface Subject {
    void method();


    /*使用场景：需要对原有方法进行修改，又不违反“对扩展开放，对修改关闭”的原则
    *           该实例属于静态代理，动态代理详见原来的例子
    * */
    public static void main(String[] args) {
        Subject subject = new Proxy();
        subject.method();
    }
}

//目标实现
class SubjectImp implements Subject{

    @Override
    public void method() {
        System.out.println("SubjectImpl method run!");
    }
}

class Proxy implements Subject{

    private Subject subject;

    public Proxy(){
        this.subject =new SubjectImp();
    }

    @Override
    public void method() {
        before();
        subject.method();
        after();
    }

    private void before(){
        System.out.println("Proxy before");
    }
    private void after(){
        System.out.println("Proxy after");
    }
}
